<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c" %> 
<%@ taglib uri="/WEB-INF/tld/ui.tld" prefix="ui" %> 
<%String path = request.getContextPath() ;%>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<jsp:include page="../../import.jsp" flush="true" />
</head>
<body class="iframeBody">
<div class="Wrapper">
<div>
		<div class="searchArea">
			<!-- 搜索表单开始 -->
			<form id="searchBar">
				<div class="fieldset1 clearFix">
					<div class="FXBR">
						<div class="fieldBox">
							<div class="label">承租人名称</div>
							<div class="field">
								<input type="text" id="cstNm" name="cstNm" class="ui-textbox" ligerui="width: 160" value="">
							</div>
						</div>
						<div class="fieldBox">
							<div class="label">合同号</div>
							<div class="field">
								<input type="text" id="contractNo" name="contractNo" class="ui-textbox" ligerui="width: 160" value="">
							</div>
						</div>
						<div class="fieldBox">
							<div class="label">支付表号</div>
							<div class="field">
								<input type="text" id="paySchNo" name="paySchNo" class="ui-textbox" ligerui="width: 160" value="">
							</div>
						</div>
						
						<div class="fieldBox">
							<div class="label">事业部</div>
							<div class="field">
								<select id="buOrgCd"  name="buOrgCd"  ligerui="width: 160">
									<option value="">请选择</option>
									<c:forEach items="${buOrgCdList}" var="item">
											<option value="${item.key}">${item.value}</option>
									</c:forEach>
								</select>
							</div>
						</div>
						<%-- <div class="fieldBox">
							<div class="label">省公司</div>
							<div class="field">
								<select id="buOrgCd2"  name="buOrgCd2"  ligerui="width: 160">
									<option value="">请选择</option>
									<c:forEach items="${prList}" var="item">
										<option value="${item.key}">${item.value}</option>
									</c:forEach>
								</select>
							</div>
						</div> --%>
						<div class="fieldBox col_33"  >
			                <div class="label">省公司</div>
			                <div class="field">
			                    <input name="cstMgrOrgCd"  id="cstMgrOrgCd" type="text" class="ui-textbox" value="">
			                </div>
			            </div>
		            
						<div class="fieldBox">
		                    <div class="label">放款时间</div>
		                    <div class="field">
		                        <input ligerui="width: 82" name="actPayTmB" id="actPayTmB" type="text" class="ui-datepicker" value="">
		                        -
		                        <input ligerui="width: 82" name="actPayTmE" id="actPayTmE" type="text" class="ui-datepicker" value="">
		                    </div>
	               	    </div>
						<div class="fieldBox">
							<div class="label">电子归档状态</div>
							<div class="field">
								<select id="eleStorageStatus"  name="eleStorageStatus"  ligerui="width: 160">
									<option value="">请选择</option>
									<c:forEach items="${archiveStateList}" var="item">
										<option value="${item.key}">${item.value}</option>
									</c:forEach>
								</select>
							</div>
						</div>
						<div class="fieldBox">
							<div class="label">纸质归档状态</div>
							<div class="field">
								<select id="storageStatus"  name="storageStatus"  ligerui="width: 160">
									<option value="">请选择</option>
									<c:forEach items="${archiveStateList}" var="item">
										<c:if test="${item.key==3 || item.key==4}">
											<option value="${item.key}">${item.value}</option>
										</c:if>
									</c:forEach>
								</select>
							</div>
						</div>
						<div class="fieldBox">
							<div class="label">快递单号</div>
							<div class="field">
								<input type="text" id="sendNum" name="sendNum" class="ui-textbox" ligerui="width: 160" value="">
							</div>
						</div>
					</div>
					<div class="clearFix"></div>
					
					<div class="btnsBox formBtns notRight">
						<span id="borrowApply" class="sq-button-round">借阅申请</span>
						<span id="searchBtn" class="sq-button-round">查询</span>
						<span id="clearBtn" class="sq-button-round">清空</span>
						<input id="resetBtn" type="reset" value="重置" class="l-button l-button-reset Hide"/>
		            </div>
		           
				</div>
			</form>
			<!-- 搜索表单结束 -->
		</div>
		<!-- 列表显示块 -->
		<div id="ligergrid1" class="sq-grid"></div>
	
</div>
</div>
<script type="text/javascript">
	var grid = null;
	
	$(function () {
		initOrgTree();//初始化省公司
	    initForm();//初始化表单
	    initGrid();//注意初始化要在initForm之后,因为在初始化grid的时候需要form参数
	    searchBtnEvent();//查询按钮事件
	    clearBtnEvent();//清空按钮事件

	    //多选支付表，发起借阅申请
	    $("#borrowApply").click(function(event) {
	    	
			var selectedRows = grid.getSelectedRows();
			console.log(JSON.stringify(selectedRows));
			console.log(selectedRows);
			
			if(selectedRows.length == 0){
				$.ligerDialog.SQalert({content: "请选择记录" , SQ_type: "warning" });
				return;
			}
			
			var contractNo = selectedRows[0].contractNo;//合同号
			var paySchNo = selectedRows[0].paySchNo;//支付表号
			if(selectedRows.length >= 2){
				//选择了2个以上的支付表,必须在同一个合同下
				for(var i=1;i<selectedRows.length;i++) {
					if(contractNo !=selectedRows[i].contractNo) {
						$.ligerDialog.SQalert({content: "必须在同一个合同下" , SQ_type: "warning" });
						return;
					}
					paySchNo = paySchNo+";"+selectedRows[i].paySchNo;//多个支付表，以分号隔开
				}
			}
			//发起申请页面
			borrowApply(contractNo,paySchNo);
			
		});
	    
	});
	
	//单选，发起借阅申请
	function borrowApply(contractNo,paySchNo){
		
		//判断客户是否逾期
		//如果当前角色为客户经理、分公司经理、城市经理（数据字典配置 ARC023）,则需要判断客户是否逾期 ，如果逾期不允许发起借阅流程
		$.ajax({
     		type: 'get',
     		dataType:'json',
     		url: '<%=path%>/archive/arcBorrowMain/checkCstOverdue.do?contractNo=' + contractNo,
     		success:function(msg){
     			if(msg.success == 1){
     				//无逾期或不是指定角色人员，可以发起借阅
     				var timestamp=new Date().getTime();
     				var param = '<%=path%>/archive/arcBorrowMain/borrowApply.do?contractNo=' + contractNo+'&paySchNoList=' + paySchNo ;
     				Add_navTab('borrowApply'+timestamp,'借阅申请',param, function () {
     					grid.reload();
     				});
     				
     			}else{
     				 $.ligerDialog.SQalert({content: msg.info,SQ_type: "error"});
     			}
     		}
     	});
		
		
		
	}
	
	//初始化表单
	function initForm(){
		$("#searchBar").ligerForm();
	}
	
	//查询参数
	function getSearchParams(){
		var form = new liger.get("searchBar");
		var data = form.getData();
		return data;
	}
	
	//初始化列表
	function initGrid(){
		$("#ligergrid1").ligerGrid({
			url:'<%=path%>/archive/arcBorrowMain/initList.do',
			method:'get',
			parms:getSearchParams(),
			columns:[
				{ display: '承租人名称', minWidth: 180,
						render:function (rowdata, rowindex, value){
							return "<span title="+rowdata.cstNm+">"+rowdata.cstNm+"</span>";
						}
				},
				{ display: '合同号', name: 'contractNo', minWidth: 180 },
				{ display: '支付表号', name: 'paySchNo', minWidth: 180 },
			    { display: '放款时间', name: 'actPayTm', width: 120 },
				{ display: '事业部', name: 'buOrgCdNm', width: 120},
				{ display: '省公司 ', name: 'prOrgCdNm', width: 120},
				/* { display: '客户经理', name: 'cstMgrNm', width: 120}, */
				{ display: '电子归档状态', name: 'eleStorageStatusNm', minWidth: 80},
				{ display: '纸质归档状态', name: 'storageStatusNm', minWidth: 80 },
				/* { display: '借阅状态', name: 'borrowStatusNm', minWidth: 80 }, */
				{
					display:'操作',
					width:220,
					render:function (rowdata, rowindex, value){
						var h="";
						h+='<a class="sq-button-hasicon" href="javascript:viewTotal(';
		            	h+="'"+rowdata.contractNo+"',";
		            	h+="'"+rowdata.paySchNo+"'";
		                h+=")\"><i class='sqBtnIco_4'></i>查看</a>";
						
			            	h+='<a class="sq-button-hasicon" href="javascript:borrowApply(';
			            	h+="'"+rowdata.contractNo+"',";
			            	h+="'"+rowdata.paySchNo+"'";
			                h+=")\"><i class='sqBtnIco_4'></i>借阅申请</a>";
						
		                	h+='<a class="sq-button-hasicon" href="javascript:flowList(';
		                	h+="'"+rowdata.contractNo+"'";
			                h+=",'"+rowdata.paySchNo+"'";
			                h+=")\"><i class='sqBtnIco_4'></i>流程信息</a>";
		                
						return h;
					}
				},
			],
			pageSize:10,
			root:'rows',
			record:'total',
			hideLoadButton:false,
			width:'100%',
			height:'100%',
			heightDiff:-2,
			isScroll: true,
			checkbox:true,//列表是否有选择框
			rownumbers:true,//列表是否有行号
			
		});
		grid = liger.get("ligergrid1");
		grid.setHeight(100);
	}
	
	
	//查看详情
	function viewDetail(paySchId,contractNo){
		
		var param = '<%=path%>/archive/arcBorrowMain/viewDetail.do?paySchId=' + paySchId+'&contractNo='+contractNo ;
		Add_navTab('arcBorrowMainViewDetail'+paySchId,'查看详情',param, function () {
			grid.reload();
		});
	}
	//查看流程
	function viewFlow(paySchId,contractNo){
		
		var param = '<%=path%>/archive/arcBorrowMain/toViewFlow.do?paySchId=' + paySchId+'&contractNo='+contractNo ;
		Add_navTab('arcBorrowMainToViewFlow'+paySchId,'查看流程',param, function () {
			grid.reload();
		});
	}
	
	
	//清空按钮事件
	function clearBtnEvent(){
		$("#clearBtn").click(function(event) {
			$("#resetBtn").click();  //重置 input-text
			var form = liger.get("searchBar");
			form.setData({  //重置select等特殊表单
				"buOrgCd":"",
				"eleStorageStatus":"",
				"cstMgrOrgCd":"",
				"storageStatus":""
			});
			//liger.get('cstMgrOrgCd').clear();
			//searchOrgTree.clear();
		});
	}
	
	//查询按钮事件
	function searchBtnEvent(){
		$("#searchBtn").click(function(event) {
			var form = new liger.get("searchBar");
			var data = form.getData();
			//alert(JSON.stringify(data));
			for (name in data){
				grid.setParm(name,data[name]);
			};
			grid.reload();
		});
	}
	
	
	//流程信息
	function flowList(contractNo,paySchNo){
		
		$.ligerDialog.SQopen({
            cls: 'noBorder_Dialog',
            width: 800,
            height:500,
            title : '借阅流程信息',
            url:'<%=path%>/archive/arcBorrowMain/flowList.do?contractNo=' + contractNo+'&paySchNo=' + paySchNo
        });
	}

	//单选，发起借阅申请
	function viewTotal(contractNo,paySchNo){
		//var timestamp=new Date().getTime();
		var param = '<%=path%>/archive/arcBorrowMain/viewTotal.do?contractNo=' + contractNo+'&paySchNoList=' + paySchNo ;
		Add_navTab('viewTotal'+paySchNo,'详情',param, function () {
			//grid.reload();
		});
	}
	
	var searchOrgTree;
	function initOrgTree(){
    	var params = {};
    	 searchOrgTree = $("#cstMgrOrgCd").ligerComboBox({
    		 width: 480,
             selectBoxWidth: 480,
             selectBoxHeight: 150,
             //限制只能选叶节点，父节点不能点击
             treeLeafOnly: false,
             valueField: 'orgCd',
             textField: 'orgDispNm',
             showTreePath: true,
             tree: {
                 ajaxType: 'get',
                 idFieldName:'orgCd',
                 textFieldName: 'orgDispNm',
                 checkbox: false,
                 parentIcon: "none",
                 childIcon: "none",
                 needCancel : false
             }
         });
    	 $.ajax({
     		type: 'get',
     		dataType:'json',
     		data: params,
     		url: '<%=path%>/warrant/warrantfilemanage/searchBuOrgTree.do',
     		success:function(msg){
     			if(msg.success == 1){
     				searchOrgTree.treeManager.setData(msg.data);
     				searchOrgTree.clear();
     				searchOrgTree.setValue('${currOrg}');
     			}else{
     				 $.ligerDialog.SQalert({content: msg.info,SQ_type: "error"});
     			}
     		}
     	});
    }    
	
	
</script>
</body>
</html>